added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2010 / VBWebDownloader / Readme.txt
blobdf41797c60b2321d8cf6f671e20408c1de3cbea4
1 ================================================================================
2                     Windows APPLICATION: VBWebDownloader
3 ===============================================================================
5 /////////////////////////////////////////////////////////////////////////////
6 Summary:
7 The sample demonstrates how to show progress during the download.
9 The class System.Net.WebClient has a DownloadProgressChanged event, and you can register
10 this event to show the progress. But this class does not support Pause/Resume.
12 The class HttpDownloadClient in this sample could be used to download data through 
13 internet and supports following features:
14 1. Set the buffer and cache size.
15 2. Download a specified block data of the whole file. 
16 3. Start, Pause, Resume and Cancel a download.  
17 4. Supply the file size, download speed and used time.
18 5. Expose the events StatusChanged, DownloadProgressChanged and DownloadCompleted.
20 NOTE: To enable the Feature2 and Feature3, the server must support the http
21       "Accept-Ranges" header. 
22    
23 ////////////////////////////////////////////////////////////////////////////////
24 Demo:
25 Step1. Build the sample project in Visual Studio 2010.
27 Step2. Run VBWebDownloader.exe
29 Step3. Type following link as url.
30 http://download.microsoft.com/download/9/5/A/95A9616B-7A37-4AF6-BC36-D6EA96C8DAAE/dotNetFx40_Full_x86_x64.exe
32 Step4. Type a local path like D:\DotNetFx4.exe.
34 Step5. Click the button "Download", you will see the status "Downloading" and the summary 
35 "Received: ***KB, Total: ***KB, Speed: ***KB/s", the progressbar will also change.
36        
37            In Windows Explorer, you will find a file  D:\DotNetFx4.exe.tmp.
39 Step6. Click the button "Pause", you will see the status "Paused" and the summary 
40 "Received: ***KB, Total: ***KB, Time: ***", the progressbar will also stop.
41        
42        If the server does not support "Accept-Ranges" header, the "Pause" button is
43        disabled. 
45 Step7. Click the button "Resume", you will see the status "Downloading" and the summary 
46 "Received: ***KB, Total: ***KB, Speed: ***KB/s", the progressbar will also change.
48 Step8. When the download completes, you will see the status "Completed" and the summary 
49 "Received: ***KB, Total: ***KB, Time: ***", the progressbar will also stop.
50        
51            In Windows Explorer, you will find a file  D:\DotNetFx4.exe.
54 /////////////////////////////////////////////////////////////////////////////
55 Code Logic:
57 1. When a HttpDownloadClient object is created, initialize the fields/properties
58    StartPoint, EndPoint, BufferSize, MaxCacheSize, BufferCountPerNotification, Url
59    DownloadPath and Status.
61 2. When the download starts, check whether the destination file exists. If not, create
62    a local file with the same size as the file to be downloaded, then download 
63    the file in a background thread.
65 3. The download thread will read a buffer of bytes from the response stream, and store the
66    buffer to a MemoryStream cache first. If the cache is full, or the download is paused, 
67    canceled or completed, write the data in cache to local file.
69 4. Raise the event DownloadProgressChanged when read a specified number of buffers.
71 5. If the download is paused, store the downloaded size. When it is resumed, start to 
72    download the file from a start point.
74 6. Update the used time and status when the current download stops.
76 7. Raise the event DownloadCompleted when the download is completed or canceled.
79 /////////////////////////////////////////////////////////////////////////////
80 References:
82 HttpWebRequest Class 
83 http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx
84 AddRange Method 
85 http://msdn.microsoft.com/en-us/library/7fy67z6d.aspx
86 How can i check if file download completed
87 http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/e115d4a1-5800-4f2a-98d8-079de6cf8a1a
88 /////////////////////////////////////////////////////////////////////////////